package de.wechselfuchs.docgenerator.ui;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTabbedPane;
import org.eclipse.wb.swing.FocusTraversalOnArray;
import java.awt.Component;
import com.jgoodies.forms.factories.DefaultComponentFactory;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.RowSpec;
import com.jgoodies.forms.factories.FormFactory;

import de.wechselfuchs.docgenerator.doc.Offer;
import de.wechselfuchs.docgenerator.tariff.Tariff;

import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.JFormattedTextField;
import java.awt.Color;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.Box;
import javax.swing.border.TitledBorder;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JCheckBox;
import javax.swing.JButton;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.text.DecimalFormat;

import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;

public class DocGenerator {

	
	/* GUI Fields */
	
	private JFrame frmWechselfuchsDocgenerator;
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextField textField_3;
	private JTextField textField_4;
	private JTextField textField_5;
	private JTextField textField_6;
	private JTextField textField_7;
	private JTextField textField_8;
	private JTextField textField_9;
	private JTextField textField_10;
	private JTextField textField_11;
	private JTextField textField_12;
	private JTextField company0;
	private JTextField company1;
	private JTextField company2;
	private JTextField company3;
	private JTextField tariff0;
	private JTextField tariff1;
	private JTextField tariff2;
	private JTextField tariff3;
	private JLabel label;
	private JComboBox bonusKind0;
	private JComboBox bonusKind1;
	private JComboBox bonusKind2;
	private JComboBox bonusKind3;
	private JLabel lblFreikwh;
	private JLabel lblAktuelleKosten;
	private JLabel lblVariante_3;
	private JLabel lblVariante_4;
	private JLabel lblVariante_5;
	private JLabel lblErsparnis;
	private JLabel lblKostenJhrlich;
	private JLabel lblZahlungsweise;
	private JComboBox paymentPeriod1;
	private JComboBox paymentPeriod2;
	private JLabel lblVertragslaufzeit;
	private JLabel lblKndigung;
	private JLabel lblStrommix;
	private JComboBox energyMix1;
	private JComboBox energyMix2;
	private JComboBox energyMix3;
	private JLabel lblPreisgarantie;
	private JTextField priceWarranty2;
	private JTextField priceWarranty3;
	private JLabel lblInsAngebot;
	private JCheckBox a1;
	private JCheckBox a2;
	private JCheckBox a3;
	private JTextField saving1;
	private JTextField saving2;
	private JTextField saving3;
	private JTextField costs1;
	private JTextField costs2;
	private JTextField costs3;
	private JButton btnRechne;
	private JSpinner basePrice0;
	private JSpinner basePrice1;
	private JSpinner basePrice2;
	private JSpinner basePrice3;
	private JSpinner workPrice1;
	private JSpinner workPrice2;
	private JSpinner workPrice3;
	private JSpinner deposit1;
	private JSpinner deposit2;
	private JSpinner deposit3;
	private JSpinner bonusHeight1;
	private JSpinner bonusHeight2;
	private JSpinner bonusHeight3;
	private JSpinner packageSize1;
	private JSpinner packageSize2;
	private JSpinner packageSize3;
	private JSpinner packagePrice1;
	private JSpinner packagePrice2;
	private JSpinner packagePrice3;
	private JSpinner moreConsumptionPrice1;
	private JSpinner moreConsumptionPrice2;
	private JSpinner moreConsumptionPrice3;
	private JSpinner windowSize1;
	private JSpinner windowSize2;
	private JSpinner windowSize3;
	private JSpinner windowPrice1;
	private JSpinner windowPrice2;
	private JSpinner windowPrice3;
	private JSpinner freeKWh1;
	private JSpinner freeKWh2;
	private JSpinner freeKWh3;
	private JSpinner consumption;
	private JSpinner oldCosts;
	private JButton btnErstelleDokument;
	private JSpinner workPrice0;
	private JSpinner deposit0;
	private JSpinner bonusHeight0;
	private JSpinner packageSize0;
	private JSpinner packagePrice0;
	private JSpinner moreConsumptionPrice0;
	private JSpinner windowSize0;
	private JSpinner windowPrice0;
	private JSpinner freeKWh0;
	private JSpinner duration1;
	private JSpinner duration2;
	private JSpinner duration3;
	private JSpinner cancellationPeriod1;
	private JSpinner cancellationPeriod2;
	private JSpinner cancellationPeriod3;
	private JSpinner priceWarranty1;
	
	/* End GUI Fields */
	
	/* More Fields */
	
	private Tariff[] electricityTariffs;
	
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					DocGenerator window = new DocGenerator();
					window.frmWechselfuchsDocgenerator.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public DocGenerator() {
		electricityTariffs = new Tariff[3];
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frmWechselfuchsDocgenerator = new JFrame();
		frmWechselfuchsDocgenerator.setFocusCycleRoot(false);
		frmWechselfuchsDocgenerator.setFocusTraversalKeysEnabled(false);
		frmWechselfuchsDocgenerator.getContentPane()
				.setFocusTraversalKeysEnabled(false);
		frmWechselfuchsDocgenerator.getContentPane().setFont(
				new Font("Calibri", Font.PLAIN, 11));
		frmWechselfuchsDocgenerator.setBackground(Color.ORANGE);
		frmWechselfuchsDocgenerator
				.setFont(new Font("Calibri", Font.PLAIN, 11));
		frmWechselfuchsDocgenerator.setTitle("Wechselfuchs Doc-Generator");
		frmWechselfuchsDocgenerator.setBounds(100, 100, 1088, 533);
		frmWechselfuchsDocgenerator
				.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		tabbedPane.setFocusTraversalPolicyProvider(true);
		tabbedPane.setFocusCycleRoot(true);
		tabbedPane.setBackground(Color.ORANGE);
		frmWechselfuchsDocgenerator.getContentPane().add(tabbedPane,
				BorderLayout.CENTER);

		JPanel panelStart = new JPanel();
		tabbedPane.addTab("Start", null, panelStart, null);
		tabbedPane.setBackgroundAt(0, Color.ORANGE);

		JPanel panelPersDaten = new JPanel();
		panelPersDaten.setBorder(new TitledBorder(null,
				"Pers\u00F6nliche Daten", TitledBorder.LEADING,
				TitledBorder.TOP, null, new Color(0, 0, 0)));
		GroupLayout gl_panelStart = new GroupLayout(panelStart);
		gl_panelStart.setHorizontalGroup(gl_panelStart.createParallelGroup(
				Alignment.LEADING).addGroup(
				gl_panelStart
						.createSequentialGroup()
						.addContainerGap()
						.addComponent(panelPersDaten,
								GroupLayout.PREFERRED_SIZE, 198,
								GroupLayout.PREFERRED_SIZE)
						.addContainerGap(596, Short.MAX_VALUE)));
		gl_panelStart.setVerticalGroup(gl_panelStart.createParallelGroup(
				Alignment.LEADING).addGroup(
				gl_panelStart
						.createSequentialGroup()
						.addContainerGap()
						.addComponent(panelPersDaten,
								GroupLayout.PREFERRED_SIZE, 373,
								GroupLayout.PREFERRED_SIZE)
						.addContainerGap(83, Short.MAX_VALUE)));
		panelPersDaten
				.setLayout(new FormLayout(new ColumnSpec[] {
						FormFactory.RELATED_GAP_COLSPEC,
						FormFactory.DEFAULT_COLSPEC,
						FormFactory.RELATED_GAP_COLSPEC,
						ColumnSpec.decode("default:grow"),
						FormFactory.RELATED_GAP_COLSPEC, }, new RowSpec[] {
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.DEFAULT_ROWSPEC,
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.DEFAULT_ROWSPEC,
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.DEFAULT_ROWSPEC,
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.DEFAULT_ROWSPEC,
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.DEFAULT_ROWSPEC,
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.DEFAULT_ROWSPEC,
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.DEFAULT_ROWSPEC,
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.DEFAULT_ROWSPEC,
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.DEFAULT_ROWSPEC,
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.DEFAULT_ROWSPEC,
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.DEFAULT_ROWSPEC,
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.DEFAULT_ROWSPEC,
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.DEFAULT_ROWSPEC, }));

		JLabel lblVorname = new JLabel("Vorname:");
		panelPersDaten.add(lblVorname, "2, 2, right, default");

		textField = new JTextField();
		panelPersDaten.add(textField, "4, 2");
		textField.setColumns(10);

		JLabel lblNachname = new JLabel("Nachname:");
		panelPersDaten.add(lblNachname, "2, 4, right, default");

		textField_1 = new JTextField();
		panelPersDaten.add(textField_1, "4, 4");
		textField_1.setColumns(10);

		JLabel lblPlz = new JLabel("PLZ:");
		panelPersDaten.add(lblPlz, "2, 6, right, default");

		textField_2 = new JTextField();
		panelPersDaten.add(textField_2, "4, 6");
		textField_2.setColumns(10);

		JLabel lblOrt = new JLabel("Ort:");
		panelPersDaten.add(lblOrt, "2, 8, right, default");

		textField_3 = new JTextField();
		panelPersDaten.add(textField_3, "4, 8");
		textField_3.setColumns(10);

		JLabel lblStrae = new JLabel("Stra\u00DFe:");
		panelPersDaten.add(lblStrae, "2, 10, right, default");

		textField_4 = new JTextField();
		panelPersDaten.add(textField_4, "4, 10");
		textField_4.setColumns(10);

		JLabel lblHausnummer = new JLabel("Hausnummer:");
		panelPersDaten.add(lblHausnummer, "2, 12, right, default");

		textField_5 = new JTextField();
		panelPersDaten.add(textField_5, "4, 12");
		textField_5.setColumns(10);

		JLabel lblGeburtstag = new JLabel("Geburtstag:");
		panelPersDaten.add(lblGeburtstag, "2, 14, right, default");

		textField_6 = new JTextField();
		panelPersDaten.add(textField_6, "4, 14, fill, default");
		textField_6.setColumns(10);

		JLabel lblNewLabel = new JLabel("Telefon:");
		panelPersDaten.add(lblNewLabel, "2, 16, right, default");

		textField_7 = new JTextField();
		panelPersDaten.add(textField_7, "4, 16, fill, default");
		textField_7.setColumns(10);

		JLabel lblEmail = new JLabel("E-Mail:");
		panelPersDaten.add(lblEmail, "2, 18, right, default");

		textField_8 = new JTextField();
		panelPersDaten.add(textField_8, "4, 18, fill, default");
		textField_8.setColumns(10);

		JLabel lblKontoinhaber = new JLabel("Kontoinhaber:");
		panelPersDaten.add(lblKontoinhaber, "2, 20, right, default");

		textField_9 = new JTextField();
		panelPersDaten.add(textField_9, "4, 20, fill, default");
		textField_9.setColumns(10);

		JLabel lblKontonummer = new JLabel("Kontonummer:");
		panelPersDaten.add(lblKontonummer, "2, 22, right, default");

		textField_10 = new JTextField();
		panelPersDaten.add(textField_10, "4, 22, fill, default");
		textField_10.setColumns(10);

		JLabel lblBankleitzahl = new JLabel("Bankleitzahl:");
		panelPersDaten.add(lblBankleitzahl, "2, 24, right, default");

		textField_11 = new JTextField();
		panelPersDaten.add(textField_11, "4, 24, fill, default");
		textField_11.setColumns(10);

		JLabel lblKreditinstitut = new JLabel("Kreditinstitut:");
		panelPersDaten.add(lblKreditinstitut, "2, 26, right, default");

		textField_12 = new JTextField();
		panelPersDaten.add(textField_12, "4, 26, fill, default");
		textField_12.setColumns(10);
		panelPersDaten.setFocusTraversalPolicy(new FocusTraversalOnArray(
				new Component[] { lblVorname, textField, lblNachname,
						textField_1, lblPlz, textField_2, lblOrt, textField_3,
						lblStrae, textField_4, lblHausnummer, textField_5,
						lblGeburtstag, textField_6, lblNewLabel, textField_7,
						lblEmail, textField_8, lblKontoinhaber, textField_9,
						lblKontonummer, textField_10, lblBankleitzahl,
						textField_11, lblKreditinstitut, textField_12 }));
		panelStart.setLayout(gl_panelStart);

		JPanel panelGas = new JPanel();
		tabbedPane.addTab("Gas", null, panelGas, null);

		JPanel panelStrom = new JPanel();
		panelStrom.setFocusTraversalPolicyProvider(true);
		tabbedPane.addTab("Strom", null, panelStrom, null);
		panelStrom
				.setLayout(new FormLayout(new ColumnSpec[] {
						FormFactory.RELATED_GAP_COLSPEC,
						FormFactory.DEFAULT_COLSPEC,
						FormFactory.RELATED_GAP_COLSPEC,
						ColumnSpec.decode("2cm:grow"),
						FormFactory.RELATED_GAP_COLSPEC,
						ColumnSpec.decode("2.3cm:grow"),
						FormFactory.RELATED_GAP_COLSPEC,
						ColumnSpec.decode("2cm:grow"),
						FormFactory.RELATED_GAP_COLSPEC,
						ColumnSpec.decode("left:2cm:grow"),
						FormFactory.RELATED_GAP_COLSPEC,
						ColumnSpec.decode("default:grow"),
						FormFactory.RELATED_GAP_COLSPEC,
						ColumnSpec.decode("default:grow"),
						FormFactory.RELATED_GAP_COLSPEC,
						ColumnSpec.decode("default:grow"),
						FormFactory.RELATED_GAP_COLSPEC,
						ColumnSpec.decode("default:grow"),
						FormFactory.RELATED_GAP_COLSPEC,
						ColumnSpec.decode("default:grow"),
						FormFactory.RELATED_GAP_COLSPEC,
						ColumnSpec.decode("default:grow"),
						FormFactory.RELATED_GAP_COLSPEC,
						ColumnSpec.decode("default:grow"),
						FormFactory.RELATED_GAP_COLSPEC,
						FormFactory.DEFAULT_COLSPEC,
						FormFactory.RELATED_GAP_COLSPEC,
						FormFactory.DEFAULT_COLSPEC,
						FormFactory.RELATED_GAP_COLSPEC, }, new RowSpec[] {
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.DEFAULT_ROWSPEC,
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.DEFAULT_ROWSPEC,
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.DEFAULT_ROWSPEC,
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.DEFAULT_ROWSPEC,
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.DEFAULT_ROWSPEC,
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.DEFAULT_ROWSPEC,
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.DEFAULT_ROWSPEC,
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.DEFAULT_ROWSPEC,
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.DEFAULT_ROWSPEC,
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.DEFAULT_ROWSPEC,
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.DEFAULT_ROWSPEC,
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.DEFAULT_ROWSPEC,
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.DEFAULT_ROWSPEC, }));

		JLabel lblCompany = new JLabel("Firma");
		panelStrom.add(lblCompany, "4, 2");

		JLabel lblTariff = new JLabel("Tarif");
		panelStrom.add(lblTariff, "6, 2");

		JLabel lblGrundpreis = new JLabel("Grundpreis");
		panelStrom.add(lblGrundpreis, "8, 2");

		JLabel lblArbeitspreis = new JLabel("Arbeitspreis");
		panelStrom.add(lblArbeitspreis, "10, 2");

		JLabel lblKaution = new JLabel("Kaution");
		panelStrom.add(lblKaution, "12, 2");

		JLabel lblBonusart = new JLabel("Bonusart");
		panelStrom.add(lblBonusart, "14, 2");

		JLabel lblBonushhe = new JLabel("Bonush\u00F6he");
		panelStrom.add(lblBonushhe, "16, 2");

		JLabel lblPaket = new JLabel("Paketgr\u00F6\u00DFe");
		panelStrom.add(lblPaket, "18, 2");

		JLabel lblPaketpreis = new JLabel("Paketpreis");
		panelStrom.add(lblPaketpreis, "20, 2");

		JLabel lblMehrverbrauchspreis = new JLabel("Mehrverbrauchspreis");
		panelStrom.add(lblMehrverbrauchspreis, "22, 2");

		label = new JLabel("Fenster");
		panelStrom.add(label, "24, 2");

		JLabel lblMehrminderverbrauchspreis = new JLabel("Fensterpreis");
		panelStrom.add(lblMehrminderverbrauchspreis, "26, 2");

		lblFreikwh = new JLabel("Frei-kWh");
		panelStrom.add(lblFreikwh, "28, 2");

		JLabel lblVergleich = new JLabel("Vergleich");
		panelStrom.add(lblVergleich, "2, 4, right, default");

		company0 = new JTextField();
		panelStrom.add(company0, "4, 4, fill, default");
		company0.setColumns(10);

		tariff0 = new JTextField();
		panelStrom.add(tariff0, "6, 4, fill, default");
		tariff0.setColumns(10);

		basePrice0 = new JSpinner();
		basePrice0.setModel(new SpinnerNumberModel(new Integer(0), null, null,
				new Integer(1)));
		panelStrom.add(basePrice0, "8, 4");

		workPrice0 = new JSpinner();
		panelStrom.add(workPrice0, "10, 4, fill, default");

		deposit0 = new JSpinner();
		panelStrom.add(deposit0, "12, 4");

		bonusKind0 = new JComboBox();
		bonusKind0.setModel(new DefaultComboBoxModel(new String[] {
				"prozentual", "fest" }));
		panelStrom.add(bonusKind0, "14, 4, fill, default");

		bonusHeight0 = new JSpinner();
		panelStrom.add(bonusHeight0, "16, 4");

		packageSize0 = new JSpinner();
		panelStrom.add(packageSize0, "18, 4");

		packagePrice0 = new JSpinner();
		panelStrom.add(packagePrice0, "20, 4");

		moreConsumptionPrice0 = new JSpinner();
		panelStrom.add(moreConsumptionPrice0, "22, 4");

		windowSize0 = new JSpinner();
		panelStrom.add(windowSize0, "24, 4");

		windowPrice0 = new JSpinner();
		panelStrom.add(windowPrice0, "26, 4");

		freeKWh0 = new JSpinner();
		panelStrom.add(freeKWh0, "28, 4");

		JLabel lblVariante = new JLabel("Variante 1");
		panelStrom.add(lblVariante, "2, 6, right, default");

		company1 = new JTextField();
		panelStrom.add(company1, "4, 6, fill, default");
		company1.setColumns(10);

		tariff1 = new JTextField();
		panelStrom.add(tariff1, "6, 6, fill, default");
		tariff1.setColumns(10);

		basePrice1 = new JSpinner();
		basePrice1.setModel(new SpinnerNumberModel(new Double(0), null, null,
				new Double(1)));
		panelStrom.add(basePrice1, "8, 6");

		workPrice1 = new JSpinner();
		workPrice1.setModel(new SpinnerNumberModel(new Double(0), null, null,
				new Double(1)));
		panelStrom.add(workPrice1, "10, 6, fill, default");

		deposit1 = new JSpinner();
		deposit1.setModel(new SpinnerNumberModel(new Double(0), null, null,
				new Double(1)));
		panelStrom.add(deposit1, "12, 6");

		bonusKind1 = new JComboBox();
		bonusKind1.setModel(new DefaultComboBoxModel(new String[] {
				"prozentual", "fest" }));
		panelStrom.add(bonusKind1, "14, 6, fill, default");

		bonusHeight1 = new JSpinner();
		bonusHeight1.setModel(new SpinnerNumberModel(new Double(0), null, null,
				new Double(1)));
		panelStrom.add(bonusHeight1, "16, 6");

		packageSize1 = new JSpinner();
		packageSize1.setModel(new SpinnerNumberModel(new Double(0), null, null,
				new Double(1)));
		panelStrom.add(packageSize1, "18, 6");

		packagePrice1 = new JSpinner();
		packagePrice1.setModel(new SpinnerNumberModel(new Double(0), null,
				null, new Double(1)));
		panelStrom.add(packagePrice1, "20, 6");

		moreConsumptionPrice1 = new JSpinner();
		moreConsumptionPrice1.setModel(new SpinnerNumberModel(new Double(0),
				null, null, new Double(1)));
		panelStrom.add(moreConsumptionPrice1, "22, 6");

		windowSize1 = new JSpinner();
		windowSize1.setModel(new SpinnerNumberModel(new Double(0), null, null,
				new Double(1)));
		panelStrom.add(windowSize1, "24, 6");

		windowPrice1 = new JSpinner();
		windowPrice1.setModel(new SpinnerNumberModel(new Double(0), null, null,
				new Double(1)));
		panelStrom.add(windowPrice1, "26, 6, fill, default");

		freeKWh1 = new JSpinner();
		freeKWh1.setModel(new SpinnerNumberModel(new Double(0), null, null,
				new Double(1)));
		panelStrom.add(freeKWh1, "28, 6");

		JLabel lblVariante_1 = new JLabel("Variante 2");
		panelStrom.add(lblVariante_1, "2, 8, right, default");

		company2 = new JTextField();
		panelStrom.add(company2, "4, 8, fill, default");
		company2.setColumns(10);

		tariff2 = new JTextField();
		panelStrom.add(tariff2, "6, 8, fill, default");
		tariff2.setColumns(10);

		basePrice2 = new JSpinner();
		basePrice2.setModel(new SpinnerNumberModel(new Double(0), null, null,
				new Double(1)));
		panelStrom.add(basePrice2, "8, 8");

		workPrice2 = new JSpinner();
		workPrice2.setModel(new SpinnerNumberModel(new Double(0), null, null,
				new Double(1)));
		panelStrom.add(workPrice2, "10, 8, fill, default");

		deposit2 = new JSpinner();
		deposit2.setModel(new SpinnerNumberModel(new Double(0), null, null,
				new Double(1)));
		panelStrom.add(deposit2, "12, 8");

		bonusKind2 = new JComboBox();
		bonusKind2.setModel(new DefaultComboBoxModel(new String[] {
				"prozentual", "fest" }));
		panelStrom.add(bonusKind2, "14, 8, fill, default");

		bonusHeight2 = new JSpinner();
		bonusHeight2.setModel(new SpinnerNumberModel(new Double(0), null, null,
				new Double(1)));
		panelStrom.add(bonusHeight2, "16, 8, default, bottom");

		packageSize2 = new JSpinner();
		packageSize2.setModel(new SpinnerNumberModel(new Double(0), null, null,
				new Double(1)));
		panelStrom.add(packageSize2, "18, 8");

		packagePrice2 = new JSpinner();
		packagePrice2.setModel(new SpinnerNumberModel(new Double(0), null,
				null, new Double(1)));
		panelStrom.add(packagePrice2, "20, 8");

		moreConsumptionPrice2 = new JSpinner();
		moreConsumptionPrice2.setModel(new SpinnerNumberModel(new Double(0),
				null, null, new Double(1)));
		panelStrom.add(moreConsumptionPrice2, "22, 8");

		windowSize2 = new JSpinner();
		windowSize2.setModel(new SpinnerNumberModel(new Double(0), null, null,
				new Double(1)));
		panelStrom.add(windowSize2, "24, 8, fill, default");

		windowPrice2 = new JSpinner();
		windowPrice2.setModel(new SpinnerNumberModel(new Double(0), null, null,
				new Double(1)));
		panelStrom.add(windowPrice2, "26, 8");

		freeKWh2 = new JSpinner();
		freeKWh2.setModel(new SpinnerNumberModel(new Double(0), null, null,
				new Double(1)));
		panelStrom.add(freeKWh2, "28, 8");

		JLabel lblVariante_2 = new JLabel("Variante 3");
		panelStrom.add(lblVariante_2, "2, 10, right, default");

		company3 = new JTextField();
		panelStrom.add(company3, "4, 10, fill, default");
		company3.setColumns(10);

		tariff3 = new JTextField();
		panelStrom.add(tariff3, "6, 10, fill, default");
		tariff3.setColumns(10);

		basePrice3 = new JSpinner();
		basePrice3.setModel(new SpinnerNumberModel(new Double(0), null, null,
				new Double(1)));
		panelStrom.add(basePrice3, "8, 10");

		workPrice3 = new JSpinner();
		workPrice3.setModel(new SpinnerNumberModel(new Double(0), null, null,
				new Double(1)));
		panelStrom.add(workPrice3, "10, 10, fill, default");

		deposit3 = new JSpinner();
		deposit3.setModel(new SpinnerNumberModel(new Double(0), null, null,
				new Double(1)));
		panelStrom.add(deposit3, "12, 10");

		bonusKind3 = new JComboBox();
		bonusKind3.setModel(new DefaultComboBoxModel(new String[] {
				"prozentual", "fest" }));
		panelStrom.add(bonusKind3, "14, 10, fill, default");

		bonusHeight3 = new JSpinner();
		bonusHeight3.setModel(new SpinnerNumberModel(new Double(0), null, null,
				new Double(1)));
		panelStrom.add(bonusHeight3, "16, 10");

		packageSize3 = new JSpinner();
		packageSize3.setModel(new SpinnerNumberModel(new Double(0), null, null,
				new Double(1)));
		panelStrom.add(packageSize3, "18, 10");

		packagePrice3 = new JSpinner();
		packagePrice3.setModel(new SpinnerNumberModel(new Double(0), null,
				null, new Double(1)));
		panelStrom.add(packagePrice3, "20, 10");

		moreConsumptionPrice3 = new JSpinner();
		moreConsumptionPrice3.setModel(new SpinnerNumberModel(new Double(0),
				null, null, new Double(1)));
		panelStrom.add(moreConsumptionPrice3, "22, 10");

		windowSize3 = new JSpinner();
		windowSize3.setModel(new SpinnerNumberModel(new Double(0), null, null,
				new Double(1)));
		panelStrom.add(windowSize3, "24, 10");

		windowPrice3 = new JSpinner();
		windowPrice3.setModel(new SpinnerNumberModel(new Double(0), null, null,
				new Double(1)));
		panelStrom.add(windowPrice3, "26, 10");

		freeKWh3 = new JSpinner();
		freeKWh3.setModel(new SpinnerNumberModel(new Double(0), null, null,
				new Double(1)));
		panelStrom.add(freeKWh3, "28, 10");

		JLabel lblVerbrauch = new JLabel("Verbrauch:");
		panelStrom.add(lblVerbrauch, "2, 14, right, default");

		consumption = new JSpinner();
		consumption.setModel(new SpinnerNumberModel(new Double(0), null, null,
				new Double(1)));
		panelStrom.add(consumption, "4, 14");

		lblAktuelleKosten = new JLabel("aktuelle Kosten:");
		panelStrom.add(lblAktuelleKosten, "6, 14, right, default");

		oldCosts = new JSpinner();
		oldCosts.setModel(new SpinnerNumberModel(new Double(0), null, null,
				new Double(1)));
		panelStrom.add(oldCosts, "8, 14");

		lblErsparnis = new JLabel("Ersparnis");
		panelStrom.add(lblErsparnis, "4, 16");

		lblKostenJhrlich = new JLabel("Kosten j\u00E4hrlich");
		panelStrom.add(lblKostenJhrlich, "6, 16");

		lblZahlungsweise = new JLabel("Zahlungsweise");
		panelStrom.add(lblZahlungsweise, "8, 16");

		lblVertragslaufzeit = new JLabel("Laufzeit");
		panelStrom.add(lblVertragslaufzeit, "10, 16");

		lblKndigung = new JLabel("K\u00FCndigung");
		panelStrom.add(lblKndigung, "12, 16");

		lblStrommix = new JLabel("Strommix");
		panelStrom.add(lblStrommix, "14, 16");

		lblPreisgarantie = new JLabel("Preisgarantie");
		panelStrom.add(lblPreisgarantie, "16, 16");

		lblInsAngebot = new JLabel("Ins Angebot?");
		panelStrom.add(lblInsAngebot, "18, 16");

		lblVariante_3 = new JLabel("Variante 1:");
		panelStrom.add(lblVariante_3, "2, 18, right, default");

		saving1 = new JTextField();
		saving1.setFocusable(false);
		saving1.setEditable(false);
		panelStrom.add(saving1, "4, 18, fill, default");
		saving1.setColumns(10);

		costs1 = new JTextField();
		costs1.setFocusable(false);
		costs1.setEditable(false);
		costs1.setColumns(10);
		panelStrom.add(costs1, "6, 18, fill, default");

		paymentPeriod1 = new JComboBox();
		paymentPeriod1
				.setModel(new DefaultComboBoxModel(new String[] {
						"j\u00E4hrlich", "halbj\u00E4hrlich", "quartal",
						"monatlich" }));
		panelStrom.add(paymentPeriod1, "8, 18, fill, default");

		duration1 = new JSpinner();
		panelStrom.add(duration1, "10, 18, fill, default");

		cancellationPeriod1 = new JSpinner();
		panelStrom.add(cancellationPeriod1, "12, 18");

		energyMix1 = new JComboBox();
		energyMix1.setModel(new DefaultComboBoxModel(new String[] { "\u00D6ko",
				"Mix" }));
		panelStrom.add(energyMix1, "14, 18, fill, default");

		priceWarranty1 = new JSpinner();
		panelStrom.add(priceWarranty1, "16, 18");

		a1 = new JCheckBox("");
		a1.setFocusable(false);
		panelStrom.add(a1, "18, 18, center, default");

		lblVariante_4 = new JLabel("Variante 2:");
		panelStrom.add(lblVariante_4, "2, 20, right, default");

		saving2 = new JTextField();
		saving2.setFocusable(false);
		saving2.setEditable(false);
		saving2.setColumns(10);
		panelStrom.add(saving2, "4, 20, fill, default");

		costs2 = new JTextField();
		costs2.setFocusable(false);
		costs2.setEditable(false);
		costs2.setColumns(10);
		panelStrom.add(costs2, "6, 20, fill, default");

		paymentPeriod2 = new JComboBox();
		paymentPeriod2
				.setModel(new DefaultComboBoxModel(new String[] {
						"j\u00E4hrlich", "hablj\u00E4hrlich", "quartal",
						"monatlich" }));
		panelStrom.add(paymentPeriod2, "8, 20, fill, default");

		duration2 = new JSpinner();
		panelStrom.add(duration2, "10, 20, fill, default");

		cancellationPeriod2 = new JSpinner();
		panelStrom.add(cancellationPeriod2, "12, 20");

		energyMix2 = new JComboBox();
		energyMix2.setModel(new DefaultComboBoxModel(new String[] { "\u00D6ko",
				"Mix" }));
		panelStrom.add(energyMix2, "14, 20, fill, default");

		priceWarranty2 = new JTextField();
		priceWarranty2.setColumns(10);
		panelStrom.add(priceWarranty2, "16, 20, fill, default");

		a2 = new JCheckBox("");
		a2.setFocusable(false);
		panelStrom.add(a2, "18, 20, center, default");

		lblVariante_5 = new JLabel("Variante 3:");
		panelStrom.add(lblVariante_5, "2, 22, right, default");

		saving3 = new JTextField();
		saving3.setFocusable(false);
		saving3.setEditable(false);
		saving3.setColumns(10);
		panelStrom.add(saving3, "4, 22, fill, default");

		costs3 = new JTextField();
		costs3.setFocusable(false);
		costs3.setEditable(false);
		costs3.setColumns(10);
		panelStrom.add(costs3, "6, 22, center, default");

		JComboBox paymentPeriod3 = new JComboBox();
		paymentPeriod3
				.setModel(new DefaultComboBoxModel(new String[] {
						"j\u00E4hrlich", "halbj\u00E4hrlich", "quartal",
						"monatlich" }));
		panelStrom.add(paymentPeriod3, "8, 22, fill, default");

		duration3 = new JSpinner();
		panelStrom.add(duration3, "10, 22, fill, default");

		cancellationPeriod3 = new JSpinner();
		panelStrom.add(cancellationPeriod3, "12, 22");

		energyMix3 = new JComboBox();
		energyMix3.setModel(new DefaultComboBoxModel(new String[] { "\u00D6ko",
				"Mix" }));
		panelStrom.add(energyMix3, "14, 22, fill, default");

		priceWarranty3 = new JTextField();
		priceWarranty3.setColumns(10);
		panelStrom.add(priceWarranty3, "16, 22, fill, default");

		a3 = new JCheckBox("");
		a3.setFocusable(false);
		panelStrom.add(a3, "18, 22, center, center");

		btnRechne = new JButton("Rechne!");
		btnRechne.addMouseListener(new ComputeSavingsMouseAdapter());
		panelStrom.add(btnRechne, "4, 26, fill, fill");

		btnErstelleDokument = new JButton("Erstelle Dokument");
		btnErstelleDokument.addMouseListener(new GenerateDocMouseAdapter());
		panelStrom.add(btnErstelleDokument, "6, 26");
	}

	/**
	 * This mouseAdapter is an inner class of the DocGenerator. It reads the
	 * input fields from the GUI, puts them into a tariff object, computes and
	 * returns the savings.
	 * 
	 * @author Sebastian Richter
	 * 
	 */

	private class ComputeSavingsMouseAdapter extends MouseAdapter {
		@Override
		public void mouseClicked(MouseEvent e) {
			
			// read input fields
			JTextField[] eFields = { saving1, saving2, saving3 };
			JTextField[] cFields = { costs1, costs2, costs3 };
			JSpinner[] bpFields = { basePrice1, basePrice2, basePrice3 };
			JSpinner[] fkFields = { freeKWh1, freeKWh2, freeKWh3 };
			JSpinner[] wpFields = { workPrice1, workPrice2, workPrice3 };
			JSpinner[] psFields = { packageSize1, packageSize2, packageSize3 };
			JSpinner[] ppFields = { packagePrice1, packagePrice2, packagePrice3 };
			JSpinner[] mcpFields = { moreConsumptionPrice1,
					moreConsumptionPrice2, moreConsumptionPrice3 };
			JSpinner[] bhFields = { bonusHeight1, bonusHeight2, bonusHeight3 };
			JComboBox[] bkFields = { bonusKind1, bonusKind2, bonusKind3 };

			// outputFormat
			DecimalFormat outputFormat = new DecimalFormat("###.##");

			// compute and output savings for each tariff
			for (int i = 0; i < eFields.length; i++) {
				// initialize new tariff object and hold in member
				electricityTariffs[i] = new Tariff();
				Tariff tariff = electricityTariffs[i];
				// set variables
				tariff.setBasePrice((Double) bpFields[i].getValue());
				tariff.setWorkPrice((Double) wpFields[i].getValue());
				tariff.setBonusHeight((Double) bhFields[i].getValue());
				if ((String) bkFields[i].getSelectedItem() == "fest") {
					tariff.setBonusKind(Tariff.FIXED_BONUS);
				} else if ((String) bkFields[i].getSelectedItem() == "prozentual") {
					tariff.setBonusKind(Tariff.PERCENT_BONUS);
				}
				tariff.setConsumption((Double) consumption.getValue());
				tariff.setFreeKWh((Double) fkFields[i].getValue());
				tariff.setMoreConsumptionPrice((Double) mcpFields[i].getValue());
				tariff.setPackagePrice((Double) ppFields[i].getValue());
				tariff.setPackageSize((Double) psFields[i].getValue());
				tariff.setOldCosts((Double) oldCosts.getValue());

				// get savings
				double savings = tariff.computeSavings();

				// output savings
				if (savings > 0) {
					eFields[i].setText(outputFormat.format(savings));
					eFields[i].repaint();
					cFields[i].setText(outputFormat.format((Double) oldCosts
							.getValue() - savings));
					cFields[i].repaint();
				}
			}
		}
	}

	private class GenerateDocMouseAdapter extends MouseAdapter {
		@Override
		public void mouseClicked(MouseEvent e) {
			// TODO Add options to tariff
			Offer ofr = new Offer(electricityTariffs);
			if(ofr.generateDoc()){
				// TODO success message
			} else {
				// TODO error message
			}
		}
	}
}
